home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Deutsche Edition 1
/
Deutsche Edition 1.iso
/
amok
/
031-040
/
amok35
/
spellchecker
/
lexi.def
< prev
next >
Wrap
Text File
|
1993-11-04
|
5KB
|
160 lines
(*********************************************************************
:Program. Lexi.def
:Contents. Basic funktions for Spellchecker
:Author. Stefan Salewski
:Copyright. PD
:Language. Modula-2
:Translator. M2Amiga AMSoft V3.3d
:History. V1.0 1.Mar.1990
:Address. Stolper Weg 3, D-2160 Stade
:Imports. TurboFilesV1.1, Assembler2V1.1 (my own)
:Imports. MemSystem (Nicolas Benezan)
*********************************************************************)
DEFINITION MODULE Lexi;
FROM Exec IMPORT UByte;
FROM TurboFiles IMPORT FilePtr;
CONST
MinWordLength=2;
MaxWordLength=14;
MinFracSizeI=6;
MinFracSizeS=4;
MinWords=10000;
MoreWords=1000;
TmpLexName='T:Lexi.tmp';
(*
InsertWord() inserts only words with
MinWordLength <= Length(word) <= maxWordLength.
SearchString divides large words in components.
If a component is found in Lexikon and
Length(thisComponent) >= MinFracSizeS then this component is
deletet from the initial string and we go on with this rest.
If Length(thisRest)>=MinFracSizeI then this rest is inserted into
the Lexikon
MinWords is the free space when we start the programm. If we
try to insert more words than MinWords, the Lexikon is saved
as TmpLexName, Space for MinWords+MoreWords is allocated and
the lexikon is loaded again.
*)
TYPE
Infos=(cap,hyphen,bHyphen);
InfoSet=SET OF Infos;
Word=ARRAY[0..MaxWordLength] OF CHAR;
PROCEDURE InitLex;
(*
Set the number of words in Lex to zero
*)
PROCEDURE ExpandLex(VAR textName:ARRAY OF CHAR):BOOLEAN;
(*
Reads words from file textName and inserts them in Lexikon.
If the word is allready in Lexikon, the counter of this word is
increased. Returns FALSE if it is not possible to open the file.
*)
PROCEDURE CleanLex(VAR cleanName:ARRAY OF CHAR):UByte;
(*
Every word has a counter (one Byte) which shows how often this
word is allready found in textfiles. CleanLex kills all words
with the lowest counter. The first call of CleanLex will kill
all words with counter=1, the next call words with counter=2 ...
RETURNS the counter of the deleted words.
*)
PROCEDURE SearchString(VAR w:ARRAY OF CHAR;VAR pos:CARDINAL;inc:UByte):BOOLEAN;
(*
Search for the string w in the lexikon. If w consists of more words,
then w is splitted in components. Returns TRUE if the word is found in
the Lexikon. In this case w and pos are undefined.
RETURNS FALSE if the word is not found. If pos#0, we can Insert()
w at position pos in Lexikon. If pos=0, we can NOT insert it, maybe
the word is too long. This procedure changes w ! For example, if
w=computertable, and table is allready in the lexikon, then we get
back w=computer and pos is the position to Insert() computer.
If a word is found in the Lexikon, then its counter is increased by inc.
*)
PROCEDURE InsertWord(VAR w:Word;pos:CARDINAL;count:UByte);
(*
Inserts w at position pos in Lexikon and sets its counter to
startvalue count. pos should be the position determed by SearchString,
because the words in Lexikon are sorted alphabetical.
*)
PROCEDURE DeleteWord(VAR w:Word):BOOLEAN;
(*
Search for w and delete it. RETURNS FALSE if word is not found.
*)
PROCEDURE SaveLex(VAR lexName:ARRAY OF CHAR):BOOLEAN;
(*
Save Lexikon to File with name lexName
*)
PROCEDURE LoadLex(VAR lexName:ARRAY OF CHAR):BOOLEAN;
(*
Load Lexikon from disk
*)
PROCEDURE ExportLex(VAR exportName:ARRAY OF CHAR):BOOLEAN;
(*
Save Lexikon to a textfile. We can use an editor to change this file
and then import it again by using ExpandLex
*)
PROCEDURE WordsInLex():CARDINAL;
(*
Returns the number of words currently in Lexikon
*)
PROCEDURE MinCount():UByte;
(*
All words in Lexikon have a counter. We set this counter to a
startvalue if we Insert() this word and increase it every
time when SearchString found this word.
MinCount() Returns the minimun count of all words in Lexikon
*)
PROCEDURE MaxCount():UByte;
(*
Returns the maximum count
*)
PROCEDURE ReadWord(source,echo:FilePtr;
VAR str:ARRAY OF CHAR;VAR info:InfoSet;
minLength,maxLength:CARDINAL);
(*
Reads a word from open file source. str contains this word if
minLength<=Length(word)<=maxLenght , otherwise str[0]=0C
If in front of this word there was '.', '?', '!', or ':' then
(cap IN info)=TRUE.
IF in front of this word there was a '-' then (hyphen IN info)=TRUE
IF in front of this word there was a CHAR(4) then
(bHyphen IN info)=TRUE
IF echo#NIL, then ReadWord writes every character that it reads
from source to echo.
*)
PROCEDURE Letter(c:CHAR):BOOLEAN;
(*
RETURNS TRUE if c is a Letter like 'A', 'a', 'ü' ...
*)
PROCEDURE Cap(c:CHAR):CHAR;
(*
Like CAP() but works although with 'ü', 'ö', ...
*)
PROCEDURE IsCap(c:CHAR):BOOLEAN;
(*
RETURNS (Cap(c)=c)
*)
END Lexi.